#!/bin/bash

# 设置环境变量
export LD_LIBRARY_PATH=/home/shadowvm/shadow/klee-change/Release+Asserts/lib:$LD_LIBRARY_PATH

#programs=("SecondV1" "SecondV2" "SecondV3" "SecondV4" "SecondV5")

#inputs=( "120 120" "120 120" "120 120" "120 120" "120 120")

programs=("FirstV1" "FirstV2" "FirstV3" "FirstV4" "FirstV5")

inputs=(  "-1 2" "3 2" "15 2" "63 2" "127 2")


declare -i j=-1
# 循环每个程序
for program in "${programs[@]}"; do
    let j++
    #echo "$j"
    cd "${programs[j]}"

    # 编译程序
    llvm-gcc -DRESOLVE_KLEE_CHANGE=0 -I/home/shadowvm/shadow/shadow-llvm-tools/include/ -emit-llvm -c eq.c -o eq.bc -std=c99

    total_execution_time=0

    # 循环每个程序执行三次
    for ((i=1; i<=3; i++)); do
        # 记录脚本开始执行的时间
        start_time=$(date +%s.%N)
	
	#
	#echo "${programs[j]} ${inputs[j]}"
	klee -posix-runtime -libc=uclibc  -emit-all-errors -max-time=600 -use -max-solver-time=30 --disable-verify eq.bc ${inputs[j]} #>/dev/null 2>&1
	

        # 记录脚本执行完毕的时间
        end_time=$(date +%s.%N)

        # 计算执行时间
        execution_time=$(echo "scale=6; ($end_time - $start_time) / 1" | bc -l)

        # 累加执行时间
        total_execution_time=$(echo "$total_execution_time + $execution_time" | bc -l)
    done

    # 计算平均执行时间
    average_execution_time=$(echo "scale=6; $total_execution_time / 3" | bc -l)

    # 输出平均执行时间
    echo "${programs[j]} eq 平均执行时间为: $average_execution_time 秒"

    # 返回上一级目录
    cd ..
done >>eq5_execution.txt
